package com.sbtr.controller;


import com.alibaba.fastjson.JSON;
import com.sbtr.business.classify.dto.AlgorithmInfoDto;
import com.sbtr.business.classify.service.IClassifyService;
import com.sbtr.common.Response;
import com.sbtr.open.classify.dto.ClassifyDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 标签表 前端控制器
 * </p>
 *
 * @author oujh5

 */
@RestController
@RequestMapping("/classify")
@Api(tags = "标签模块（包括标签增删改查+建模时候算法获取）")
public class ClassifyController {

	@Autowired
	private IClassifyService classifyService;

	private Logger logger = LoggerFactory.getLogger(ClassifyController.class);
	
	@ApiOperation(value = "新增", notes = "新增", httpMethod = "POST")
	@PostMapping(value = "/save")
	public Response<ClassifyDto> saveClassify(@RequestBody ClassifyDto dto){
		logger.info("新增：{}",JSON.toJSON(dto));
		return Response.success("保存成功", classifyService.saveClassify(dto));
	}
	
	@ApiOperation(value = "修改", notes = "修改", httpMethod = "POST")
	@PostMapping(value = "/update")
	public Response<ClassifyDto> updateClassify(@RequestBody ClassifyDto dto){
		logger.info("修改：{}",JSON.toJSON(dto));
		return Response.success("修改成功", classifyService.updateClassify(dto));
	}
//
	@ApiOperation(value = "标签删除", notes = "根据标签id删除", httpMethod = "DELETE")
	@DeleteMapping(value = "/delete/{id}")
	public Response<Boolean> delete(@PathVariable("id") Long id){
		logger.info("标签删除：{}",id);
		boolean b = classifyService.deleteClassify(id);
		if(b){
			return Response.success("删除成功", b);
		}else{
			return Response.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), "删除失败");
		}
	}

	@ApiOperation(value = "批量保存标签", notes = "批量保存标签", httpMethod = "POST")
	@RequestMapping(value = "/{id}/batchSave", method = RequestMethod.POST)
	public Response<Boolean> batchSave(@PathVariable("id") Long calibrationId,
															@RequestBody List<ClassifyDto> dtos) {
		return Response.success(classifyService.batchSave(calibrationId, dtos));
	}



	
//	@ApiOperation(value = "根据标定集id查询标签统计信息 type 0是当前数据 1是历史数据 默认是当前数据", notes = "根据标定集id查询标签统计信息 type 0是当前数据 1是历史数据 默认是当前数据", httpMethod = "GET")
//	@GetMapping(value = "/search-by-calibration-set-id")
//	public Response<List<ClassifyInfo>> searchByCalibrationSetId(@RequestParam(name="calibrationId") Long calibrationId,@RequestParam(name="type",required = false) Long type){
//		if(null == type) {
//			type = 0L;
//		}
//		return Response.success(classifyService.searchByCalibrationSetId(calibrationId,type));
//	}
	
	@ApiOperation(value = "根据标定集id查询", notes = "根据标定集id查询", httpMethod = "GET")
	@GetMapping(value = "/search")
	public Response<List<ClassifyDto>> search(@RequestParam(name="calibrationId", required=false) Long calibrationId){
		logger.info("根据标定集id查询：{}",calibrationId);
		return Response.success(classifyService.search(calibrationId));
	}
	
	@ApiOperation(value = "获取可选算法信息", notes = "获取可选算法信息", httpMethod = "GET")
	@GetMapping(value = "/get-algorithm-info")
	public Response<List<AlgorithmInfoDto>> getAlgorithmInfo(){
		List<AlgorithmInfoDto> algorithmInfoDto= classifyService.getaAlgorithmInfo();
		return Response.success(algorithmInfoDto);
	}

	/**
	 * 模型管理
	 * 新建模型：填写信息-》选择数据集-》训练模型（首先根据算法类型加载相关算法列表信息）
	 * @param projectType
	 * @return
	 */
	@ApiOperation(value = "获取可选算法信息", notes = "填写信息-》选择数据集-》训练模型（首先根据算法类型加载相关算法列表信息）", httpMethod = "GET")
	@GetMapping(value = "/get-algorithm-by-type")
	public Response<List<AlgorithmInfoDto>> getAlgorithmInfoByProjectType(
			@RequestParam(name="projectType") String projectType
	){
		List<AlgorithmInfoDto> algorithmInfoDto= classifyService.getAlgorithmInfoByProjectType(projectType);
		return Response.success(algorithmInfoDto);
	}


//	@ApiOperation(value = "获取可选算法信息", notes = "获取可选算法信息", httpMethod = "GET")
//	@GetMapping(value = "/get-nlp-algorithm")
//	public Response<List<NlpAlgorithmDto>> getNlpAlgorithm(){
//		List<NlpAlgorithmDto> algorithmDto= classifyApi.getNlpAlgorithm();
//		return Response.success(algorithmDto);
//	}


}

